using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using DukeyCssFetch.api;
using DukeyCssFetch.auth.mou18.com;
using DukeyCssFetch.Properties;

namespace DukeyCssFetch.UI
{
	// Token: 0x02000037 RID: 55
	public class CssFetchFrm : KryptonForm
	{
		// Token: 0x06000234 RID: 564 RVA: 0x0001BBD4 File Offset: 0x00019DD4
		public CssFetchFrm()
		{
			this.string_0 = "error";
			this.string_1 = "";
			
			this.InitializeComponent();
		}

		// Token: 0x06000235 RID: 565 RVA: 0x0001BC00 File Offset: 0x00019E00
		private void btnALLDownload_Click(object sender, EventArgs e)
		{
			this.method_1(this.cbCssbianma.SelectedIndex);
			this.method_3(SaveType.Archive);
			this.method_5(LinkType.Relative);
			if (this.thread_1 == null)
			{
				this.thread_1 = new Thread(new ThreadStart(this.method_6));
			}
			if (this.thread_1.ThreadState == System.Threading.ThreadState.Unstarted)
			{
				this.thread_1.Start();
				this.btnALLDownload.Enabled = false;
			}
			if (this.thread_1.ThreadState == System.Threading.ThreadState.Suspended)
			{
				this.thread_1.Resume();
				this.btnALLDownload.Enabled = false;
			}
		}

		// Token: 0x06000237 RID: 567 RVA: 0x0001BCC8 File Offset: 0x00019EC8
		private void btnBrowser_Click(object sender, EventArgs e)
		{
			if (this.folderBrowserDialog_0.ShowDialog() == DialogResult.OK)
			{
				this.txtFolder.Text = this.folderBrowserDialog_0.SelectedPath;
			}
		}

		// Token: 0x06000239 RID: 569 RVA: 0x0001BD28 File Offset: 0x00019F28
		private void CssFetchFrm_Load(object sender, EventArgs e)
		{
			this.cbCssbianma.SelectedIndex = 0;
			this.kryptonManager_0.GlobalPaletteMode = Comm.skin;
			Control.CheckForIllegalCrossThreadCalls = false;
		}

		// Token: 0x0600023F RID: 575 RVA: 0x0001C334 File Offset: 0x0001A534
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}

		// Token: 0x06000240 RID: 576 RVA: 0x0001C354 File Offset: 0x0001A554
		private void InitializeComponent()
		{
			this.icontainer_0 = new Container();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(CssFetchFrm));
			this.btnBrowser = new KryptonButton();
			this.txtFolder = new KryptonTextBox();
			this.txtUrl = new KryptonTextBox();
			this.linkLabel1 = new LinkLabel();
			this.label3 = new Label();
			this.label5 = new Label();
			this.lblTip = new Label();
			this.groupBox1 = new GroupBox();
			this.btnALLDownload = new KryptonButton();
			this.cbCssbianma = new ComboBox();
			this.folderBrowserDialog_0 = new FolderBrowserDialog();
			this.kryptonManager_0 = new KryptonManager(this.icontainer_0);
			this.toolTip_0 = new ToolTip(this.icontainer_0);
			this.linkLabel2 = new LinkLabel();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.btnBrowser.AutoSize = true;
			this.btnBrowser.Location = new Point(381, 55);
			this.btnBrowser.Name = "btnBrowser";
			this.btnBrowser.Size = new Size(90, 25);
			this.btnBrowser.TabIndex = 41;
			this.btnBrowser.Values.Text = "浏览文件夹";
			this.btnBrowser.Click += new EventHandler(this.btnBrowser_Click);
			this.txtFolder.Location = new Point(97, 58);
			this.txtFolder.Name = "txtFolder";
			this.txtFolder.Size = new Size(278, 20);
			this.txtFolder.TabIndex = 39;
			this.txtFolder.Text = "D:\\仿站";
			this.txtFolder.WordWrap = false;
			this.txtUrl.Location = new Point(97, 28);
			this.txtUrl.Name = "txtUrl";
			this.txtUrl.Size = new Size(445, 20);
			this.txtUrl.TabIndex = 40;
			this.txtUrl.Text = "http://";
			this.txtUrl.WordWrap = false;
			this.linkLabel1.AutoSize = true;
			this.linkLabel1.Location = new Point(489, 63);
			this.linkLabel1.Name = "linkLabel1";
			this.linkLabel1.Size = new Size(53, 12);
			this.linkLabel1.TabIndex = 38;
			this.linkLabel1.TabStop = true;
			this.linkLabel1.Text = "打开目录";
			this.linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
			this.label3.AutoSize = true;
			this.label3.Location = new Point(26, 43);
			this.label3.Name = "label3";
			this.label3.Size = new Size(77, 12);
			this.label3.TabIndex = 36;
			this.label3.Text = "当前css路径:";
			this.label5.AutoSize = true;
			this.label5.Location = new Point(44, 62);
			this.label5.Name = "label5";
			this.label5.Size = new Size(47, 12);
			this.label5.TabIndex = 37;
			this.label5.Text = "保存到:";
			this.lblTip.AutoSize = true;
			this.lblTip.ForeColor = Color.Red;
			this.lblTip.Location = new Point(12, 164);
			this.lblTip.Name = "lblTip";
			this.lblTip.Size = new Size(173, 12);
			this.lblTip.TabIndex = 42;
			this.lblTip.Text = "欢迎你使用都客单个css下载器!";
			this.groupBox1.Controls.Add(this.linkLabel2);
			this.groupBox1.Controls.Add(this.btnALLDownload);
			this.groupBox1.Controls.Add(this.linkLabel1);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.btnBrowser);
			this.groupBox1.Controls.Add(this.cbCssbianma);
			this.groupBox1.Controls.Add(this.txtFolder);
			this.groupBox1.Controls.Add(this.txtUrl);
			this.groupBox1.Location = new Point(12, 12);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(560, 132);
			this.groupBox1.TabIndex = 43;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "参数设置";
			this.btnALLDownload.AutoSize = true;
			this.btnALLDownload.Location = new Point(452, 95);
			this.btnALLDownload.Name = "btnALLDownload";
			this.btnALLDownload.Size = new Size(90, 25);
			this.btnALLDownload.TabIndex = 32;
			this.btnALLDownload.Values.Text = "立即下载";
			this.btnALLDownload.Click += new EventHandler(this.btnALLDownload_Click);
			this.cbCssbianma.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbCssbianma.FormattingEnabled = true;
			this.cbCssbianma.Items.AddRange(new object[]
			{
				"Css编码自动检测",
				"utf-8",
				"gb2312"
			});
			this.cbCssbianma.Location = new Point(97, 98);
			this.cbCssbianma.Name = "cbCssbianma";
			this.cbCssbianma.Size = new Size(132, 20);
			this.cbCssbianma.TabIndex = 31;
			this.linkLabel2.AutoSize = true;
			this.linkLabel2.Location = new Point(270, 101);
			this.linkLabel2.Name = "linkLabel2";
			this.linkLabel2.Size = new Size(143, 12);
			this.linkLabel2.TabIndex = 42;
			this.linkLabel2.TabStop = true;
			this.linkLabel2.Text = "批量下载(原2.5版本功能)";
			this.linkLabel2.LinkClicked += new LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
			base.AutoScaleDimensions = new SizeF(6f, 12f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(590, 189);
			base.Controls.Add(this.lblTip);
			base.Controls.Add(this.label3);
			base.Controls.Add(this.groupBox1);
			base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.MaximizeBox = false;
			base.Name = "CssFetchFrm";
			base.ShowIcon = false;
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "都客单个css下载";
			base.TopMost = true;
			base.Load += new EventHandler(this.CssFetchFrm_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}

		// Token: 0x06000236 RID: 566 RVA: 0x0001BC98 File Offset: 0x00019E98
		private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			string text = this.txtFolder.Text.Trim();
			if (Directory.Exists(text))
			{
				Process.Start(text);
			}
		}

		// Token: 0x0600023E RID: 574 RVA: 0x0001C2FC File Offset: 0x0001A4FC
		private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			base.TopMost = false;
			BatDownLoadFrm batDownLoadFrm = new BatDownLoadFrm("", this.txtFolder.Text.Trim());
			batDownLoadFrm.ShowDialog();
		}

		// Token: 0x0600022E RID: 558 RVA: 0x0001BB98 File Offset: 0x00019D98
		[CompilerGenerated]
		private int method_0()
		{
			return this.int_0;
		}

		// Token: 0x0600022F RID: 559 RVA: 0x0001BBA0 File Offset: 0x00019DA0
		[CompilerGenerated]
		private void method_1(int value)
		{
			this.int_0 = value;
		}

		// Token: 0x0600023D RID: 573 RVA: 0x0001C268 File Offset: 0x0001A468
		private IList<string> method_10(string string_2, string string_3)
		{
			List<string> list = new List<string>();
			Regex regex = new Regex(string_3, RegexOptions.IgnoreCase);
			MatchCollection matchCollection = regex.Matches(string_2);
			if (matchCollection != null && matchCollection.Count > 0)
			{
				foreach (Match match in matchCollection)
				{
					if (!list.Contains(match.Value))
					{
						list.Add(match.Value);
					}
				}
			}
			return list;
		}

		// Token: 0x06000230 RID: 560 RVA: 0x0001BBAC File Offset: 0x00019DAC
		[CompilerGenerated]
		private SaveType method_2()
		{
			return this.saveType_0;
		}

		// Token: 0x06000231 RID: 561 RVA: 0x0001BBB4 File Offset: 0x00019DB4
		[CompilerGenerated]
		private void method_3(SaveType value)
		{
			this.saveType_0 = value;
		}

		// Token: 0x06000232 RID: 562 RVA: 0x0001BBC0 File Offset: 0x00019DC0
		[CompilerGenerated]
		private LinkType method_4()
		{
			return this.linkType_0;
		}

		// Token: 0x06000233 RID: 563 RVA: 0x0001BBC8 File Offset: 0x00019DC8
		[CompilerGenerated]
		private void method_5(LinkType value)
		{
			this.linkType_0 = value;
		}

		// Token: 0x06000238 RID: 568 RVA: 0x0001BCF0 File Offset: 0x00019EF0
		private void method_6()
		{
			this.btnALLDownload.Enabled = false;
			this.method_7(this.txtUrl.Text.Trim());
			this.btnALLDownload.Enabled = true;
			this.thread_1 = null;
		}

		// Token: 0x0600023A RID: 570 RVA: 0x0001BD4C File Offset: 0x00019F4C
		private void method_7(string string_2)
		{
			string_2.Remove(0, string_2.LastIndexOf("/") + 1);
			int num = string_2.LastIndexOf("//");
			int num2 = string_2.LastIndexOf("/");
			string text = string_2.Remove(num2, string_2.Length - num2) + "/";
			text = ((num2 == num + 1) ? (string_2 + "/") : text);
			Uri uri = new Uri(text);
			string str = uri.Host + "\\";
			string text2 = this.txtFolder.Text.Trim().StartsWith("\\") ? this.txtFolder.Text.Trim() : (this.txtFolder.Text.Trim() + "\\");
			text2 += str;
			this.lblTip.Text = "正在下载css文件:" + string_2;
			Encoding uTF = Encoding.UTF8;
			Dictionary<string, string> replacelist = new Dictionary<string, string>();
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			this.method_9(string_2, uTF, text2, ref replacelist, ref dictionary, this.method_4(), this.method_2(), FileType.Css);
			string text3 = "";
			Encoding encoding = this.method_8(uTF);
			string regkey = Settings.Default.regkey;
			this.string_1 = WMICardGrab.GetSHA1MachineCode();
			if (regkey == "" || Comm.api.Encrypt(this.string_1) != regkey)
			{
				MessageBox.Show("请支持正版,谢谢合作!官方唯一网址:http://www.mou18.com");
				Process.Start("http://www.mou18.com");
				Environment.Exit(0);
			}
			Comm.DownFile(string_2, text2, ref text3, replacelist, encoding, FileType.Css, string_2, ref dictionary, this.method_4(), this.method_2());
			this.lblTip.Text = "任务完成!";
			if (string.IsNullOrEmpty(Settings.Default.email))
			{
				Environment.Exit(0);
			}
			this.btnALLDownload.Enabled = false;
			this.thread_1 = null;
		}

		// Token: 0x0600023B RID: 571 RVA: 0x0001BF40 File Offset: 0x0001A140
		private Encoding method_8(Encoding encoding_0)
		{
			Encoding result = Encoding.UTF8;
			switch (this.cbCssbianma.SelectedIndex)
			{
			case 0:
				result = encoding_0;
				return result;
			case 2:
				result = Encoding.GetEncoding("gb2312");
				return result;
			}
			result = Encoding.UTF8;
			return result;
		}

		// Token: 0x0600023C RID: 572 RVA: 0x0001BF8C File Offset: 0x0001A18C
		private void method_9(string string_2, Encoding encoding_0, string string_3, ref Dictionary<string, string> dictionary_0, ref Dictionary<string, string> dictionary_1, LinkType linkType_1, SaveType saveType_1, FileType fileType_0)
		{
			this.lblTip.Text = "正在提取css中背景图片...";
			try
			{
				int num = string_2.LastIndexOf("/");
				string uriString = string_2.Remove(num, string_2.Length - num) + "/";
				Uri baseUri = new Uri(uriString);
				string text = Comm.Html(string_2, encoding_0);
				string string_4 = "(?is)(?<=[\\s\\S]*url\\()[^)]+(?=\\))";
				string pattern = "@import\\s+[^\"]*[(\"]+([^)\";]+)";
				Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
				MatchCollection matchCollection = regex.Matches(text);
				text = text.Replace("\"", "");
				text = text.Replace("'", "");
				IList<string> list = this.method_10(text, string_4);
				for (int i = 0; i < list.Count; i++)
				{
					Uri uri = new Uri(baseUri, list[i].Trim());
					if (list[i].ToLower().Contains(".css"))
					{
						this.lblTip.Text = "发现@import css" + list[i];
						this.method_9(uri.ToString(), encoding_0, string_3, ref dictionary_0, ref dictionary_1, linkType_1, saveType_1, fileType_0);
						string text2 = "";
						Comm.DownFile(uri.ToString(), string_3, ref text2, dictionary_0, encoding_0, FileType.ImportCss, list[i], ref dictionary_1, linkType_1, saveType_1);
					}
					else
					{
						this.lblTip.Text = "正在下载背景图片:" + uri.ToString();
						Comm.Download(uri.ToString(), list[i], string_3, "", ref dictionary_0, saveType_1, linkType_1, true, FileType.CssBackGroundImg);
					}
				}
				for (int j = 0; j < matchCollection.Count; j++)
				{
					Match match = matchCollection[j];
					string text3 = match.Value;
					text3 = Comm.api.RexReplace(text3, new string[]
					{
						"@import",
						"url",
						"(",
						")",
						" ",
						"\"",
						"'"
					}, "");
					string href = text3;
					if (!text3.Contains("http://") && !text3.Contains("https://"))
					{
						Uri uri2 = new Uri(baseUri, text3.Trim());
						text3 = uri2.ToString();
					}
					this.lblTip.Text = "发现@import css" + text3;
					this.method_9(text3, encoding_0, string_3, ref dictionary_0, ref dictionary_1, linkType_1, saveType_1, fileType_0);
					string text4 = "";
					Comm.DownFile(text3, string_3, ref text4, dictionary_0, encoding_0, FileType.ImportCss, href, ref dictionary_1, linkType_1, saveType_1);
				}
			}
			catch (Exception ex)
			{
				this.lblTip.Text = ex.Message;
			}
		}

		// Token: 0x04000258 RID: 600
		private bool bool_0;

		// Token: 0x04000265 RID: 613
		private KryptonButton btnALLDownload;

		// Token: 0x0400025C RID: 604
		private KryptonButton btnBrowser;

		// Token: 0x04000264 RID: 612
		private ComboBox cbCssbianma;

		// Token: 0x04000256 RID: 598
		private dukeyauth dukeyauth_0;

		// Token: 0x04000266 RID: 614
		private FolderBrowserDialog folderBrowserDialog_0;

		// Token: 0x04000263 RID: 611
		private GroupBox groupBox1;

		// Token: 0x0400025B RID: 603
		private IContainer icontainer_0;

		// Token: 0x0400026A RID: 618
		[CompilerGenerated]
		private int int_0;

		// Token: 0x04000267 RID: 615
		private KryptonManager kryptonManager_0;

		// Token: 0x04000260 RID: 608
		private Label label3;

		// Token: 0x04000261 RID: 609
		private Label label5;

		// Token: 0x04000262 RID: 610
		private Label lblTip;

		// Token: 0x0400025F RID: 607
		private LinkLabel linkLabel1;

		// Token: 0x04000269 RID: 617
		private LinkLabel linkLabel2;

		// Token: 0x0400026C RID: 620
		[CompilerGenerated]
		private LinkType linkType_0;

		// Token: 0x0400026B RID: 619
		[CompilerGenerated]
		private SaveType saveType_0;

		// Token: 0x04000255 RID: 597
		private string string_0;

		// Token: 0x04000259 RID: 601
		private string string_1;

		// Token: 0x04000257 RID: 599
		private Thread thread_0;

		// Token: 0x0400025A RID: 602
		private Thread thread_1;

		// Token: 0x04000268 RID: 616
		private ToolTip toolTip_0;

		// Token: 0x0400025D RID: 605
		private KryptonTextBox txtFolder;

		// Token: 0x0400025E RID: 606
		private KryptonTextBox txtUrl;
	}
}
